home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 September / LiquidLibrary 2005 Sep - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_typ32.ps < prev    next >
Text File  |  2003-01-03  |  4KB  |  118 lines

  1. %    Copyright (C) 1997 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % Initialization file for Type 32 fonts.
  7.  
  8. % ------ Type 32 fonts ------ %
  9.  
  10. % We need LanguageLevel 2 or higher in order to have defineresource.
  11. languagelevel dup 2 max .setlanguagelevel
  12.  
  13. /BitmapFontInit mark
  14.  
  15. /.makeglyph32 systemdict /.makeglyph32 get
  16. systemdict /.makeglyph32 .undef
  17.  
  18. /addglyph {    % ([wx wy llx lly urx ury] |
  19.         %     [w0x w0y llx lly urx ury w1x w1y vx vy])
  20.         %   <bitmap> <cid> <type32font> addglyph -
  21.   1 index dup 2 index .removeglyphs
  22.   22 string .makeglyph32
  23.         % Stack: metrics bitmap cid font metstr
  24.   3 index () ne {
  25.         % Use G4 encoding to compress the bitmap.
  26.         % Define a string large enough to hold the metrics,
  27.         % an uncompressed bitmap (worst case = 5x expansion),
  28.         % and the 2 RTC codes (3 bytes).
  29.     dup length 4 index length 5 mul add 10 add string
  30.         % Stack: metrics bitmap cid font metstr buffer
  31.     dup 0 3 index putinterval
  32.     dup 2 index length 1 index length 1 index sub getinterval
  33.         % Stack: metrics bitmap cid font metstr buffer bitbuf
  34.     mark /Columns 8 index dup 4 get exch 2 get sub
  35.       /Rows 10 index dup 5 get exch 3 get sub
  36.       /K -1 /EndOfBlock true /BlackIs1 true
  37.     .dicttomark /CCITTFaxEncode filter
  38.         % Stack: metrics bitmap cid font metstr buffer filter
  39.     dup 6 index writestring closefile
  40.         % Find the end of the data by scanning backwards for the RTC.
  41.         % There are 2 RTCs x 12 bits = 3 bytes to remove.
  42.     {
  43.       dup dup length 1 sub get 0 ne { exit } if
  44.       0 1 index length 1 sub getinterval
  45.     } loop
  46.     0 1 index length 3 sub getinterval
  47.     exch pop    % metstr
  48.   } if
  49.   1 index /CharStrings get 3 index 3 -1 roll put
  50.   pop pop pop pop
  51. } obind
  52.  
  53. /removeall {        % <type32font> removeall -
  54.   0 65535 2 index removeglyphs pop
  55. } obind
  56.  
  57. /.removeglyphs systemdict /.removeglyphs get
  58. systemdict /.removeglyphs .undef
  59.  
  60. /removeglyphs {        % <cid_min> <cid_max> <type32font> .removeglyphs -
  61.   3 copy .removeglyphs
  62.   dup /CharStrings get dup {
  63.         % Stack: cidmin cidmax font CharStrings cid bitmap
  64.     pop dup 5 index ge { dup 4 index le { 2 copy undef } if } if pop
  65.   } forall pop pop pop pop
  66. } obind
  67.  
  68. .dicttomark /ProcSet defineresource pop
  69.  
  70. /.cidfonttypes where { pop } { /.cidfonttypes 6 dict def } ifelse
  71. .cidfonttypes begin
  72.  
  73. 4    % CIDFontType 4 = FontType 32
  74. { dup /FontType 32 put
  75.   dup /CharStrings 20 dict put
  76.   1 index exch .buildfont32 exch pop
  77. } bind def
  78.  
  79. end        % .cidfonttypes
  80.  
  81. % Define the BuildGlyph procedure.
  82. % Since Type 32 fonts are indexed by CID, there is no BuildChar procedure.
  83. % The name %Type32BuildGlyph is known to the interpreter.
  84. (%Type32BuildGlyph) cvn {    % <font> <cid> %Type32BuildGlyph -
  85.   1 index /CharStrings get
  86.         % Stack: font cid CharStrings
  87.   dup 2 index .knownget
  88.  { exch pop } { 0 get } ifelse
  89.         % Stack: font cid cstr
  90.   dup //.getmetrics32    % use // because of .undef below
  91.   dup 14 gt {
  92.     8 index 8 index 13 3 roll setcachedevice2
  93.   } {
  94.     4 index 4 index 9 3 roll setcachedevice
  95.   } ifelse
  96.         % Stack: font cid cstr w h nmetrics llx lly
  97.   6 -1 roll 4 -1 roll 1 index length 1 index sub getinterval
  98.         % Stack: font cid w h llx lly bitstr
  99.   dup () eq {
  100.     pop pop pop
  101.   } {
  102.     mark /Columns 6 index /Rows 7 index /K -1 /EndOfBlock false /BlackIs1 true
  103.     .dicttomark /CCITTFaxDecode filter 4 index 4 index true
  104.         % Stack: font cid w h llx lly filter w h true
  105.     [ 1 0 0 1 11 -2 roll exch neg exch neg ] 5 -1 roll imagemask
  106.   } ifelse
  107.   pop pop pop pop
  108. } bind def
  109.  
  110. systemdict /.getmetrics32 .undef
  111.  
  112. buildfontdict 32 /.buildfont32 cvx put
  113.  
  114. 32 dup /FontType defineresource pop
  115.  
  116. .setlanguagelevel
  117.